<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/27 0027
 * Time: 9:54
 */

namespace app\admin\controller;


use think\Loader;
use think\Request;

class Base extends \app\jointly\controller\Base
{
    public $validate;
    public $data;
    public function __construct()
    {
        parent::__construct();
        //todo 验证规则
        $this->validate = Loader::validate(Request::instance()->controller());
        $method = Request::instance()->method();
        switch ($method){
            case 'POST';
                $data = Request::instance()->post();
                break;
            case 'GET';
                $data = Request::instance()->get();
                break;
            default:
                exit($this->encode('请求错误'));
        }
        $this->data = $data;
        $action = Request::instance()->action();
        if(!$this->validate->scene($action)->check($data))exit($this->encode($this->validate->getError(),0));
    }
}